using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraEditors;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace WorkGroup.Controls
{
    public class WgButtonEdit : ButtonEdit, IWgControl
    {
        private Keys shortcutKeys;
        private string languageCode;
        private Control focusedControl;
        private Control labelControl;

        [Bindable(true)]
        [Category("WorkGroup")]
        [DefaultValue("")]
        [Localizable(true)]
        public Keys ShortcutKeys
        {
            get { return shortcutKeys; }
            set { shortcutKeys = value; }
        }

        [Bindable(true)]
        [Category("WorkGroup")]
        [DefaultValue("")]
        [Localizable(true)]
        public string LanguageCode
        {
            get
            {
                return languageCode;
            }
            set
            {
                languageCode = value;
            }
        }

        [Bindable(true)]
        [Category("WorkGroup")]
        [DefaultValue("")]
        [Localizable(true)]
        public Control LabelControl
        {
            get { return labelControl; }
            set { labelControl = value; }
        }

        [Bindable(true)]
        [Category("WorkGroup")]
        [DefaultValue("")]
        [Localizable(true)]
        public Control FocusedControl
        {
            get { return focusedControl; }
            set { focusedControl = value; }
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.KeyCode == Keys.Enter)
                if (focusedControl != null)
                    focusedControl.Focus();
        }
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            if (labelControl != null)
                labelControl.Font = new Font(labelControl.Font.FontFamily, labelControl.Font.Size, FontStyle.Bold);

            this.BackColor = Color.LemonChiffon;
        }
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
            if (labelControl != null)
                labelControl.Font = new Font(labelControl.Font.FontFamily, labelControl.Font.Size, FontStyle.Regular);

            this.BackColor = Color.White;
        }

        public void SetFont(FontFamily fontName, int size, FontStyle style)
        {
            this.Font = new Font(fontName, size, style);
        }

    }
}
